﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace HelperPrototype.OtherForms
{
    public partial class XemPhieuDeNghiMuaHangForm : Form
    {
        string _maPhieu = null;
        _DB.PhieuDeNghiMuaHang p = null;

        public XemPhieuDeNghiMuaHangForm(String MaPhieu)
        {
            InitializeComponent();
            _maPhieu = MaPhieu;
        }

        private void XemPhieuDeNghiMuaHangForm_Load(object sender, EventArgs e)
        {
            loadData();

            _DB.DataClasses1DataContext dc = new _DB.DataClasses1DataContext();
            p = dc.PhieuDeNghiMuaHangs.Single(phieu => phieu.MaPhieu == _maPhieu);

            txtMaPhieu.Text = p.MaPhieu;
            txtNguoiTao.Text = p.NguoiTao.Ten;
            txtPhongBan.Text = (p.NguoiTao.PhongBan != null) ? p.NguoiTao.PhongBan.TenPhongBan : "";
            txtNgayTao.Text = p.NgayTao.ToLongTimeString();
            txtNgayHan.Text = p.NgayHan.ToLongTimeString();
            txtNoiDung.Text = p.NoiDung;
            txtTrangThai.Text = p.QuyTrinhMuaHangs.Single().TrangThaiQuyTrinhMuaHang.MoTa;

            // fill grid hang hoa
            dgvHangHoa.Rows.Clear();
            int count = 1;
            foreach (_DB.PhieuDeNghiMuaHang_HangHoa h in p.PhieuDeNghiMuaHang_HangHoas)
            {
                DataGridViewRow r = new DataGridViewRow();
                r.CreateCells(dgvHangHoa);
                r.Cells[0].Value = count++;
                r.Cells[1].Value = h.HangHoa.TenHangHoa;
                r.Cells[2].Value = h.SoLuongDeNghi;
                r.Cells[3].Value = h.HangHoa.DonVi;
                r.Cells[4].Value = h.NhaCungCapThamKhao;
                r.Cells[5].Value = h.GiaThamKhao;

                dgvHangHoa.Rows.Add(r);
            }
        }

        private void loadData()
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            loadData();
        }

        private void btnQuyTrinh_Click(object sender, EventArgs e)
        {
            XemQuyTrinh f = new XemQuyTrinh(p.QuyTrinhMuaHangs.Single().ID);
            f.Show();
        }
    }
}
